package com.example.deertrip;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.deertrip.database.DBOperate;

public class login_admin_Activity extends AppCompatActivity{
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_admin);

        EditText adminname;
        EditText adminpassword;
        adminname=(EditText) findViewById(R.id.login_admin_zhanghao);
        adminpassword=(EditText) findViewById(R.id.login_admin_mima);

        Button admin_denglu1;
        admin_denglu1=(Button) findViewById(R.id.login_admin_denglu1);


        admin_denglu1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String name=adminname.getText().toString();
                System.out.println(name);
                String pass=adminpassword.getText().toString();
                System.out.println(pass);

                //  Log.i("TAG",name+"_"+pass);
                DBOperate dboperate=new DBOperate(login_admin_Activity.this);
                boolean flag=dboperate.adminlogin(name, pass);
                if(flag){

                    SharedPreferences sp=getSharedPreferences("deertrip",MODE_PRIVATE);
                    SharedPreferences.Editor editor = sp.edit();
                    editor.putInt("login_state",2);
                    editor.commit();

                    Log.i("TAG","登录成功");
                    Toast.makeText(login_admin_Activity.this, "登录成功", Toast.LENGTH_LONG).show();
                    Intent intent = new Intent(login_admin_Activity.this,Worker_main.class);
                    startActivity(intent);
                }else{
                    Log.i("TAG","登录失败");
                    Toast.makeText(login_admin_Activity.this, "登录失败", Toast.LENGTH_LONG).show();
                }

            }
        });
    }
}
